package com.leetcode.No3174;

import org.junit.Test;

public class Solution {
    public String clearDigits(String s) {
        int len = s.length();
        int leftDelete = 0;
        char[] chars = new char[len];
        int offset = len;
        for (int i = len - 1; i >= 0; --i) {
            char ch = s.charAt(i);
            if (ch >= '0' && ch <= '9') {
                ++leftDelete;
            } else {
                if (leftDelete > 0) {
                    --leftDelete;
                } else {
                    chars[--offset] = ch;
                }
            }
        }
        return String.valueOf(chars, offset, len - offset);
    }

    @Test
    public void test() {
        String str1 = "abc";
        System.out.println(clearDigits(str1));

        String str2 = "ab1c";
        System.out.println(clearDigits(str2));

        String str3 = "2abc";
        System.out.println(clearDigits(str3));

        String str4 = "12";
        System.out.println(clearDigits(str4));

        String str5 = "ab12";
        System.out.println(clearDigits(str5));
    }
}
